package net.exoweb.samples
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    import net.exoweb.animate.actions.*;
    import net.exoweb.animate.animaters.*;
    import net.exoweb.animate.common.*;
    import net.exoweb.animate.events.*;
    import net.exoweb.animate.graphics.*;
    import net.exoweb.animate.objects.*;

    [SWF(width="1280", height="720", backgroundColor="#000000")]
    public class NuclearEngine extends Sprite
    {
        //[Embed(source="background.png")]
        //private var backImage:Class;
        //private var background:Bitmap = new backImage();
        private var timer:Time;
        private var full:Boolean;

        private var ray:GRay;
        private var nuclear:GNuclear;
        private var menu:GMenu;
        private var screen:GScreen;

        public function NuclearEngine()
        {
            x = 640;
            y = 360;
            full = false;
            timer = new Time();

            /*background.x = -640;
            background.y = -360;
            background.scaleX = 2.5;
            background.scaleY = 2.5;
            background.alpha = 0.5;
            addChild(background);*/

            ray = new GRay(300, 0, 0xFFFF00, 0xFF0000);
            ray.display();
            ray.x = 0;
            ray.y = 0;
            addChild(ray);

            nuclear = new GNuclear();
            nuclear.alpha = 1;
            nuclear.x = 530;
            nuclear.y = -320;
            nuclear.buttonMode = true;
            nuclear.display();
            addChild(nuclear);
            nuclear.addEventListener(MouseEvent.MOUSE_DOWN, fullScreen);

            menu = new GMenu(0x80A0FF);
            menu.display();
            menu.x = -600;
            menu.y = -300;
            addChild(menu);
            //menu.addEventListener(MouseEvent.MOUSE_OVER, displayMenu);

            screen = new GScreen(0x80A0FF);
            screen.display();
            addChild(screen);

            addEventListener(Event.ENTER_FRAME, update);
        }

        public function downMenu(e:Event):void
        {
            if(menu.y + 10 >= -300)
            {
                menu.y = -300;
                removeEventListener(Event.ENTER_FRAME, downMenu);
                menu.removeEventListener(MouseEvent.MOUSE_OVER, displayMenu);
                menu.addEventListener(MouseEvent.MOUSE_OUT, undisplayMenu);
            }
            else
            {
                menu.y += 10;
            }
        }

        public function displayMenu(e:Event):void
        {
            addEventListener(Event.ENTER_FRAME, downMenu);
        }

        public function upMenu(e:Event):void
        {
            if(menu.y - 10 <= -600)
            {
                menu.y = -600;
                removeEventListener(Event.ENTER_FRAME, upMenu);
                menu.removeEventListener(MouseEvent.MOUSE_OUT, undisplayMenu);
                menu.addEventListener(MouseEvent.MOUSE_OVER, displayMenu);
            }
            else
            {
                menu.y -= 10;
            }
        }

        public function undisplayMenu(e:Event):void
        {
            addEventListener(Event.ENTER_FRAME, upMenu);
        }

        public function lightRay():void
        {
            ray.toX = mouseX;
            ray.toY = mouseY;
        }

        public function fullScreen(e:Event):void
        {
            if(full)
            {
                full = false;
                stage.displayState = "normal";
            }
            else
            {
                full = true;
                stage.displayState = "fullScreen";
            }
        }

        public function update(e:Event):void
        {
            var t:Number = timer.interval();
            timer.next();
            lightRay();
        }
    }
}
